package com.jacobson.huobi.utils

import android.content.Context
import android.content.SharedPreferences
import android.preference.PreferenceManager

/** 设置参数类 */
object SettingProperties {
    /** 卖出铃声分类 */
    const val KEY_RING_SELL = "key_ring_sell"
    /** 买入铃声分类 */
    const val KEY_RING_BUY = "key_ring_buy"
    /** 是否静音 */
    const val KEY_IS_MUTE = "key_is_mute"
    /** 买入是否使用TTS播报 */
    const val KEY_USE_TTS_BUY = "key_use_tts_buy"
    /** 卖出是否使用TTS播报 */
    const val KEY_USE_TTS_SELL = "key_use_tts_sell"
    /** 买入铃声 */
    const val KEY_RINGTONE_BUY = "key_ringtone_buy"
    /** 卖出铃声 */
    const val KEY_RINGTONE_SELL = "key_ringtone_sell"
    /** 买入语音项 */
    const val KEY_TTS_BUY_ITEMS = "key_tts_buy_items"
    /** 卖出语音项 */
    const val KEY_TTS_SELL_ITEMS = "key_tts_sell_items"
    /** 最小交易量 */
    const val KEY_MIN_VOLUME_VALUE = "key_min_volume_value"

    /** 用户token信息 */
    const val KEY_USER_TOKEN_INFO = "key_user_token_info"

    const val KEY_USER_LOGIN_TIMER_INFO = "key_user_login_timer_info"

    //登陆手机号
    const val KEY_LOGIN_PHONE = "_key_login_phone_"
    //登陆密码
    const val KEY_LOGIN_PASSWORD = "_key_login_password_"



    private lateinit var preferences: SharedPreferences
    /** 报警设置项 */
    const val KEY_TTS_ALARM_ITEMS = "key_tts_alarm_items"
    /** 初始化 */
    fun init(context: Context) {
        preferences = PreferenceManager.getDefaultSharedPreferences(context)
    }

    /** 是否静音 */
    fun isMute() = preferences.getBoolean(KEY_IS_MUTE, false)

    /** 买入是否使用语音播放 */
    fun isUseTtsBuy() = preferences.getBoolean(KEY_USE_TTS_BUY, true)

    /** 卖出是否使用语音播放 */
    fun isUseTtsSell() = preferences.getBoolean(KEY_USE_TTS_SELL, true)

    /** 买入铃声 */
    fun getRingtoneBuy(): String? = preferences.getString(KEY_RINGTONE_BUY, null)

    /** 卖出铃声 */
    fun getRingtoneSell(): String? = preferences.getString(KEY_RINGTONE_SELL, null)

    /** 最小交易量 */
    fun getMinVolumeValue(): String? {
        var value = preferences.getString(KEY_MIN_VOLUME_VALUE, "0")
        if (value.isEmpty()) {
            return "0"
        }else {
            return value
        }
    }
    /** 报警设置 */
    fun getAlramSetting(): String? = preferences.getString(KEY_TTS_ALARM_ITEMS, "4H报警")

    /** 语音播报类型 */
    fun getRingtoneTTSItems(): String {
        var result = ""
        var buyStr = preferences.getStringSet(KEY_TTS_BUY_ITEMS, hashSetOf()).toString().trim().replace("[","").replace("]","")
        var sellStr = preferences.getStringSet(KEY_TTS_SELL_ITEMS, hashSetOf()).toString().trim().replace("[","").replace("]","")
        result += buyStr
        if (sellStr.length > 0 ) {
            result = result + ", " + sellStr
        }
        return result
    }

    fun setUserTokenInfo(info: String) {
        var editor = preferences.edit()
        editor.putString(KEY_USER_TOKEN_INFO, info)
        editor.apply()
    }

    fun getUserTokenInfo(): String? = preferences.getString(KEY_USER_TOKEN_INFO, null)

    fun setCommonValue(key: String, value: String) {
        var editor = preferences.edit()
        editor.putString(key, value)
        editor.apply()
    }

    fun getCommonValue(key: String): String? = preferences.getString(key, "")



    fun setUserLoginTimerInfo(info: Int) {
        var editor = preferences.edit()
        editor.putInt(KEY_USER_LOGIN_TIMER_INFO, info)
        editor.apply()
    }

    fun getUserLoginTimerInfo(): Int? = preferences.getInt(KEY_USER_LOGIN_TIMER_INFO, 0)


}